//
//  ChoiceRecordViewController.m
//  RSW.IOS
//
//  Created by zhaiqiuqiu on 17/1/12.
//  Copyright © 2017年 com.xtion.crm. All rights reserved.
//

#import "ChoiceRecordViewController.h"
#import "KZVideoViewController.h" 
#import "KZVideoPlayer.h"

NSString *const ChoiceRecordViewControllerChoiceRecordParamKey = @"ChoiceRecordViewControllerChoiceRecordParamKey";

@interface ChoiceRecordViewController ()<KZVideoViewControllerDelegate>
{
    KZVideoModel *_videoModel;
}
@end

@implementation ChoiceRecordViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self checkSession];
    [self setBackNavigateItemTitle:@"录像" rightItemText:@"确定"];
    self.view.backgroundColor = [UIColor blackColor];

    KZVideoViewController *videoVC = [[KZVideoViewController alloc] init];
    videoVC.delegate = self;
    [videoVC startAnimationWithType:KZVideoViewShowTypeSingle];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

#pragma mark - KZVideoViewControllerDelegate
- (void)videoViewController:(KZVideoViewController *)videoController didRecordVideo:(KZVideoModel *)videoModel {
    _videoModel = videoModel;
    
    NSURL *videoUrl = [NSURL fileURLWithPath:_videoModel.videoAbsolutePath];
    CGSize videoViewSize = [KZVideoConfig videoViewDefaultSize];
    KZVideoPlayer *player = [[KZVideoPlayer alloc] initWithFrame:CGRectMake(0, self.view.height/2.0, videoViewSize.width, videoViewSize.height) videoUrl:videoUrl];
    player.centerY = self.view.centerY;
    
    [self.view addSubview:player];
}

- (void)videoViewControllerDidCancel:(KZVideoViewController *)videoController {
    NSLog(@"没有录到视频");
    
    [XUINavigationController pop];
}

-(void)clickedRightBarButton:(id)sender
{
    XUIViewControllerSwitchParam *p = [XUIViewControllerSwitchParam new];
    p.param[ChoiceRecordViewControllerChoiceRecordParamKey] = _videoModel;
    [XUINavigationController popWithSwitchParam:p];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
